﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaggingToolkit.Framework
{
    public class TagCount : IHighlightItem
    {
        public string Name { get; private set; }
        public int Count { get; private set; }
        public bool Changed { get; private set; }
        public bool HighlightEnabled => Changed;
        public Color HighlightColor => Color.DarkRed;


        public string DisplayName
        {
            get
            {
                if (action == TagEditAction.Rename)
                {
                    return $"{Name} -> {newName}";
                }
                else
                {
                    return Name;
                }
            }
        }

        private TagEditAction action = TagEditAction.Keep;
        public TagEditAction Action {
            get => action;
            set
            {
                action = value;
                if (action == TagEditAction.Remove || action == TagEditAction.AddFront || action == TagEditAction.AddBack)
                {
                    newName = Name;
                    Changed = true;
                }
                else if(action == TagEditAction.Keep)
                {
                    newName = Name;
                    Changed = false;
                }
            }
        }

        private string newName;
        public string NewName
        {
            get => newName;
            set
            {
                newName = value;
                if(action == TagEditAction.AddFront || action == TagEditAction.AddBack)
                {
                    Name = value;
                }
                else
                {
                    if (!newName.Equals(Name))
                    {
                        action = TagEditAction.Rename;
                        Changed = true;
                    }
                    else
                    {
                        action = TagEditAction.Keep;
                        Changed = false;
                    }
                }
            }
        }

        public TagCount(string name, int count)
        {
            Name = newName = name;
            Count = count;
        }
    }
}
